﻿using System;
using System.Collections.Generic;
using System.Linq;
using Data.Entities;
using Microsoft.Practices.Unity;
using Repository.Interface;
using Service.Interface;

namespace Service
{
    /// <summary>
    /// 学生服务类
    /// </summary>
    public class StudentService : IStudentService
    {
        #region service
        [Dependency]
        public IStudentRepository StudentRepository { get; set; }
        #endregion

        #region 获取学生
        /// <summary>
        /// 获取学生
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>学生实体</returns>
        public Student Get(Guid id)
        {
            return StudentRepository.Get(id);
        }
        #endregion

        #region 根据主键删除学生
        /// <summary>
        /// 根据主键删除学生
        /// </summary>
        /// <param name="id">主键</param>
        public void Delete(Guid id)
        {
            StudentRepository.Delete(id);
        }
        #endregion

        #region 新增一个学生
        /// <summary>
        /// 新增一个学生
        /// </summary>
        /// <param name="student"></param>
        public void Add(Student student)
        {
            StudentRepository.Add(student);
        }
        #endregion

        #region 根据泛型委托获取所有学生集合
        /// <summary>
        /// 根据泛型委托获取所有学生集合
        /// </summary>
        /// <param name="func">泛型委托</param>
        /// <returns>学生集合</returns>
        public IList<Student> FindAll(Func<Student, bool> func)
        {
            if (func == null) return StudentRepository.FindAll(c => true).ToList();
            return StudentRepository.FindAll(func).ToList();
        }
        #endregion
    }
}